package com.yuedao.sender.service1;

import cn.ydx.protobuf.OTIpcDef;
import com.yuedao.sender.util.AppLogger;
import com.yuedao.sender.util.ByteUtil;
import com.yuedao.sender.util.HttpSender;
import org.springframework.stereotype.Service;

@Service
public class BaseService {

	/*@Value("${company.id}")
	protected String companyId;
	
	@Value("${company.source}")
	protected String companySource;*/
	//pro:8580     test:1874
	protected String baseURL = "http://220.248.104.170:1874/redisBridge";
	

	protected final static String companyId = "yuedao";
	
	protected final static String companySource = "0";
	
	protected static AppLogger logger = AppLogger.getInstance();
	
	/**
	 * 压缩数据并推送
	 */
	protected String compressAndSend(String targetURL,OTIpcDef.OTIpc otIpc){
		
		OTIpcDef.OTIpcList otipcList = OTIpcDef.OTIpcList.newBuilder()
                .addOtpic(otIpc).build();
		
		byte[] content = null;
        try {
            content = ByteUtil.compress(otipcList.toByteArray());// 对数据进行压缩
        } catch (Exception e) {
            e.printStackTrace();
        }
       
		if(content != null){
		//调用发送方法，将请求发送过去
		System.out.println(baseURL+targetURL.trim());
		String message=HttpSender.executePost(baseURL+targetURL.trim(), content, true, false);
		logger.info(message);
		System.out.println(message);
		return message;
		}
		return "";
	}
	
}
